<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>公积金查询</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="../../plugins/mui/mui.min.css">
    <link rel="stylesheet" href="../../css/my/fund/index.css"/>
    <script src="../../js/statistics.js"></script>
    <script src="../../js/fontset.js"></script>
</head>
<body>
<header class="mui-bar mui-bar-nav header">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 class="mui-title">公积金查询</h1>
</header>
<div class="mui-content">
	<div class="banner">
		<img src="../../images/my/fund/fund-banner-1.png" alt="背景图" />
		<div class="fund-userInfo">
			<span class="userInfo-tit">账户余额（元）</span>
			<span class="userInfo-money"><span>***</span><i class="icon icon-hide"></i></span>
			<span class="userInfo-detail"><span>**</span><span>*****</span></span>
			<div class="userInfo-btn-box">
				<button class="btn" id="lookInfo">查看账户信息</button>
			</div>
		</div>
	</div>
	<div class="fund-list">
		<div class="fund-cell ">
			<div class=" cell-item" data-href="fund-detail.html" data-type="deposite">
				<img src="../../images/my/fund/icon-jc.png" alt="我的缴存" />
				<span>我的缴存</span>
			</div>
			<div class=" cell-item" data-href="fund-detail.html" data-type="extract">
				<img src="../../images/my/fund/icon-tq.png" alt="我的提取" />
				<span>我的提取</span>
			</div>
		</div>
		<div class="fund-cell mui-row">
			<div class=" cell-item" data-href="fund-statement.html">
				<img src="../../images/my/fund/icon-dz.png" alt="对账查询" />
				<span>对账查询</span>
			</div>
			<div class="cell-item" data-href="fund-loan.html">
				<img src="../../images/my/fund/icon-dk.png" alt="个人贷款" />
				<span>个人贷款</span>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="../../plugins/jquery/jquery-3.1.0.min.js"></script>
<script src="../../plugins/mui/mui.min.js"></script>
<!--<script type="text/javascript" src="../plugins/mui/update.js"></script>-->
<script src="../../js/getApiToken.js"></script>
<script src="../../js/md5.js"></script>
<script src="../../js/my/security/index.js" ></script>
<script src="../../js/life_housekeeper/windowTitleView.js"></script>
<script type="text/javascript">
    mui.init({
// 				statusBarBackground: '#43ac45',  //ios下设置顶部背景色
    });
	mui.plusReady(function(){
		var self = plus.webview.currentWebview(),
			spcode = plus.storage.getItem('spcode')|| self.spcode;
		var fundLogin = self.opener();
		if(fundLogin && fundLogin.id == 'fund-login.html'){
			fundLogin.close();
		}
		getBaseInfo(spcode);		
	})
	
	function getBaseInfo(spcode){
		plus.nativeUI.showWaiting();
		myAjax('home/provident/getBaseInfo','post',{
			spcode:spcode
		},function(e){
			plus.nativeUI.closeWaiting();
			if(e.code == 0){
				//console.log(JSON.stringify(e.data));
				if(!e.data.body || e.data.body == ''){
					return;
				}
				var userInfo = e.data.body.list.acc_info[0],
					tranTime= e.data.head.trantime || new Date().getFullYear() + '',
					tranYear = tranTime.substring(0,4),
					totalMoney = (mathCount(userInfo.spmend) + mathCount(userInfo.btye)).toFixed(2),
					money = formatCurrency(totalMoney),
					name = replaceStr(userInfo.spname);
				document.querySelectorAll('.userInfo-detail')[0].innerHTML = '<span>'+name+'</span><span>'+userInfo.spcode+'</span>'
				mui('.userInfo-money').on('tap','i.icon',function(e){
					if($(this).hasClass('icon-hide')){
						$(this).removeClass('icon-hide').addClass('icon-show');
						$(this).prev().html(money);
					}else{
						$(this).removeClass('icon-show').addClass('icon-hide');
						$(this).prev().html('***');
					}
				})
				mui('.fund-userInfo').on('tap','#lookInfo',function(e){
					console.log(e);
					var viewOptions = {
						url:'fund-info.html',
						id:'fund-info'
					},
					extras ={
						info:userInfo,
						time:tranYear
					},
					titleOptions = {
						title:'公积金查询',
						backImg:'whiteBack'
					};
					addTitleView(viewOptions,extras,titleOptions);
				});
				mui('.fund-list').on('tap','.cell-item',function(e){
					var _this = this,
						dataHref = _this.getAttribute('data-href').trim(),
						type = _this.getAttribute('data-type') || '';
					var viewOptions = {
						url:dataHref,
						id:dataHref
					},
					extras ={
						type:type,
						spcode:spcode,
						time:tranYear
					},
					titleOptions = {
						backImg:'whiteBack'
					};
					addTitleView(viewOptions,extras,titleOptions);
					
				})
			}else{
				mui.toast(e.message);
			}
		});
	}
	function mathCount(e){
		var count = e.split(',');
		var str = '';
		for(var i = 0; i < count.length; i += 1){
			str += count[i];
		}
		return Number(str);
	}
	function formatCurrency(num) {
        if(num)
        {
            //将num中的$,去掉，将num变成一个纯粹的数据格式字符串
            num = num.toString().replace(/\$|\,/g,'');
            //如果num不是数字，则将num置0，并返回
            if(''==num || isNaN(num)){return 'Not a Number ! ';}
            //如果num是负数，则获取她的符号
            var sign = num.indexOf("-")> 0 ? '-' : '';
            //如果存在小数点，则获取数字的小数部分
            var cents = num.indexOf(".")> 0 ? num.substr(num.indexOf(".")) : '';
            cents = cents.length>1 ? cents : '' ;//注意：这里如果是使用change方法不断的调用，小数是输入不了的
            //获取数字的整数数部分
            num = num.indexOf(".")>0 ? num.substring(0,(num.indexOf("."))) : num ;
            //如果没有小数点，整数部分不能以0开头
            if('' == cents){ if(num.length>1 && '0' == num.substr(0,1)){return 'Not a Number ! ';}}
            //如果有小数点，且整数的部分的长度大于1，则整数部分不能以0开头
            else{if(num.length>1 && '0' == num.substr(0,1)){return 'Not a Number ! ';}}
            //针对整数部分进行格式化处理，这是此方法的核心，也是稍难理解的一个地方，逆向的来思考或者采用简单的事例来实现就容易多了
            /*
              也可以这样想象，现在有一串数字字符串在你面前，如果让你给他家千分位的逗号的话，你是怎么来思考和操作的?
              字符串长度为0/1/2/3时都不用添加
              字符串长度大于3的时候，从右往左数，有三位字符就加一个逗号，然后继续往前数，直到不到往前数少于三位字符为止
             */
            for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            {
                num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
            }
            //将数据（符号、整数部分、小数部分）整体组合返回
            return (sign + num + cents);    
        }
   }
</script>
</body>
</html>
